package com.wy.ifly.mvp;

import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.wy.ifly.R;
import com.wy.ifly.mvp.b.GoodBean;
import com.wy.ifly.mvp.p.GoodPresenter;
import com.wy.ifly.mvp.v.IGoodView;

import java.util.List;

public class MvpActivity extends BaseActivity<GoodPresenter, IGoodView> implements IGoodView {


    private String TAG = "MvpActivity";

    private ListView lvList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvp);

        init();

        lvList = findViewById(R.id.lvList);

        presenter.fetch();

    }

    private void init() {
        //绑定监听者，被监听者关系
        getLifecycle().addObserver(presenter);
    }

    @Override
    protected GoodPresenter<IGoodView> createPresenter() {
        return new GoodPresenter();
    }

    @Override
    public void startLoadData() {

    }

    @Override
    public void showData(List<GoodBean> list) {

        ListAdapter listAdapter = new ListAdapter(this, list);
        lvList.setAdapter(listAdapter);

        Log.i(TAG, "list:" + list.toString());
    }

    @Override
    public void showError(String msg) {
        Log.i(TAG, "msg:" + msg);
    }


}